// $codepro.audit.disable
package edu.gatech.oad.cyberdoc.view.container;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.util.logging.Logger;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.json.JSONException;
import org.json.JSONObject;

import edu.gatech.oad.cyberdoc.view.LoginComponentsPanel;

@SuppressWarnings("serial")
public class LoginPanel extends ContainerPanel {

	/**
	 * This class's logger.
	 */
	private static final Logger LOG;

	private LoginComponentsPanel componentsPanel;

	static {
		LOG = Logger.getLogger("edu.gatech.oad.cyberdoc.view.MainFrame");
	}

	/**
	 * Create the panel.
	 */
	public LoginPanel() {
		super(null, "");
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		JPanel panel = new JPanel();
		add(panel);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

		Component rigidArea = Box.createRigidArea(new Dimension(4, 0));
		panel.add(rigidArea);

		JLabel lblLogin_1 = new JLabel("Login");
		lblLogin_1.setFont(new Font("Lucida Grande", Font.PLAIN, 22));
		panel.add(lblLogin_1);

		Component horizontalGlue = Box.createHorizontalGlue();
		panel.add(horizontalGlue);

		Component rigidArea_2 = Box.createRigidArea(new Dimension(0, 8));
		add(rigidArea_2);

		JPanel descriptionPanel = new JPanel();
		add(descriptionPanel);
		descriptionPanel.setLayout(new BoxLayout(descriptionPanel,
				BoxLayout.X_AXIS));

		Component rigidArea2 = Box.createRigidArea(new Dimension(4, 0));
		descriptionPanel.add(rigidArea2);

		JLabel lblWelcomeToCyberdoc = new JLabel(
				"<html>Welcome to Cyberdoc, the medical office management system.  To begin, please enter your username and password.</html>");
		descriptionPanel.add(lblWelcomeToCyberdoc);
		lblWelcomeToCyberdoc.setFont(new Font("Lucida Grande", Font.PLAIN, 12));

		Component horizontalGlue_1 = Box.createHorizontalGlue();
		descriptionPanel.add(horizontalGlue_1);

		Component rigidArea_4 = Box.createRigidArea(new Dimension(0, 20));
		add(rigidArea_4);

		JPanel usernamePanel = new JPanel();
		add(usernamePanel);
		usernamePanel.setLayout(new BoxLayout(usernamePanel, BoxLayout.X_AXIS));

		Component rigidArea_3 = Box.createRigidArea(new Dimension(12, 0));
		usernamePanel.add(rigidArea_3);

		componentsPanel = new LoginComponentsPanel();
		// componentsPanel.setMaximumSize(new Dimension(800, 800));
		usernamePanel.add(componentsPanel);
	}

	public String toString() {
		return "LoginPanel";
	}

	@Override
	public void show(JSONObject response) {
		try {
			if (response.has("error_message")) {
				String error = response.getString("error_message");
				componentsPanel.setError(error);
			}
		} catch (JSONException e) {
			LOG.info("Response does not contain error_message field");
		}
	}

	@Override
	public void show(String panel, JSONObject response) {
		throw new UnsupportedOperationException();
	}
}
